<?php

/**
 * 线上测试工具
 *
 * @author camfee <camfee@foxmail.com>
 */

define('SITE_AUTH', 'safety-test');
require('../../../common.inc.php');

use Center\EnrollUser;
use Center\User;
use Center\UserRelationship;

class test extends \lib\core\AdminAction
{
    public function doDefault()
    {
        $smarty = $this->app->page();

        $smarty->output('safety/test.tpl');
    }

    // 清除用户支付状态
    public function doClear()
    {
        $uid = intval($_POST['uid']);
        $type = $_POST['type'];
        if (empty($type)) {
            self::output(['title' => '缺少清除类型', 'type' => 'error']);
        }
        if (!in_array($uid, [826271, 589795, 589789, 718042])) {
            self::output(['title' => '非测试用户，不能清除', 'type' => 'error']);
        }

        foreach ($type as $v) {
            switch ($v) {
                case 'enroll':
                    $r1 = EnrollUser::update($uid, ['Status' => EnrollUser::STATUS_WAIT_PAY, 'PayId' => 0]);
                    break;
                case 'user_type':
                    $r2 = User::updateUser($uid, [User::FIELD_USER_TYPE => User::USER_TYPE_NORMAL]);
                    break;
                case 'invite':
                    $r3 = UserRelationship::deleteData($uid);
                    break;
            }
        }

        self::output(['title' => '清除成功', 'type' => 'success']);
    }
}

$app->run();